package com.leaf.u_spring.chapter13;


import java.util.ArrayList;
import java.util.List;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.support.CompositeCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @EnableCaching启用注解
 *
 */
@Configuration
@EnableCaching		
public class CompositeCachingConfig {

	/**
	 * 声明缓存管理器  
	 * 
	 * CompositeCacheManager会迭代JCacheCacheManager、EhCacheCacheManager、RedisCacheManager
	 * @param cm
	 * @return
	 */
	@Bean
	public CacheManager cacheManager(net.sf.ehcache.CacheManager cm) {
		CompositeCacheManager cacheManager = new CompositeCacheManager();
		
		List<CacheManager> cacheManagers = new ArrayList<CacheManager>();
//		cacheManagers.add(new JCacheCacheManager(jm));
//		cacheManagers.add(new EhCacheCacheManager(cm));
//		cacheManagers.add(new RedisCacheManager(redisTemplate()));
		cacheManager.setCacheManagers(cacheManagers);
		
		return cacheManager;
	}
	
	
  
}